package com.vgooo.client.mobile;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.vgooo.bean.MobileAlbum;
import com.vgooo.client.R;
import com.vgooo.util.BitmapUtils;

public class MobileAlbumAdapter extends BaseAdapter {

	private List<MobileAlbum> albums ;//产品图赏信息
	private LayoutInflater inflater ;
	private Context context ;
	
	
	
	
	public MobileAlbumAdapter(List<MobileAlbum> albums, Context context) {
		super();
		setAlbums(albums);
		this.context = context;
		inflater = LayoutInflater.from(context);
	}

	public void setAlbums(List<MobileAlbum> albums) {
		if(albums!=null){
			this.albums = albums;
		}else{
			this.albums = new ArrayList<MobileAlbum>() ;  
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return albums.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return albums.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder  holder = null ;
		if(convertView == null ){
			convertView = inflater.inflate(R.layout.mobile_album_item_small, null) ;
			holder = new ViewHolder() ;
			holder.image = (ImageView) convertView.findViewById(R.id.mobile_album_small_item_image);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag() ;
		}
//		String urlPath = albums.get(position).image_src ;
		BitmapUtils.loaderImage(albums.get(position).image_src , holder.image ,context);
		return convertView;
	}
	
	
	class ViewHolder{
		ImageView image ;
	}

}
